/**
 * 远光ECP平台3.0版本 http://www.ygsoft.com/ Grace [Gris Application Cloud-Computing
 * Extension]
 * 
 * 原生window窗口，双屏处理
 * 
 * 变更版本：
 * zhengxianwei@ygsoft.com 2016-06-21 创建
 */
define(["jquery","ecp.utils","jquery.migrate"], function($,utils){
	/**
	 * 默认参数.
	 */
	var defaultOption = {
        title: "新建窗口",
        exWidth: 3500,
        exHeight: 2000
	}
	var ExtendWindow = function(url,option){
		this.init(url,option);
	}
	
	ExtendWindow.prototype = {
		/**
	     * 初始化控件
	     * 
	     * @control 控件
	     */
		init : function(url, option){
	    	if(typeof (url) === "undefined" || url.length === 0){return;}
	    	this.url = url;
	    	// 窗口其他选项默认值
		    this.option = $.extend(true, {}, defaultOption, option);
		    this.render();
		},
		render : function(){
			var option = this.option;//option.width option.height
			var exHeight;
			if($.browser.safari){
				exHeight = window.innerHeight;
			}else{
				exHeight = option.exHeight;
			}
			var opt = this._windowParams(option.exWidth,exHeight);
			var uuid = Math.uuid();
			window["_template_"+uuid] = option;
			//增加url可能已经带参数的情况，改成用&符号
			var uuidParam = "?ctxuuid="+uuid;
			if (this.url && this.url.indexOf("?") != -1){
				uuidParam = "&ctxuuid="+uuid;
			}
			this._window = window.open(this.url + uuidParam, "extendWindowName", opt);
		},
		close : function(){
			if(this._window){
				this._window.close();
			}
		},
		_windowParams : function(width, height) {
		    var a = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft;
		    var i = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop;
		    var g = typeof window.outerWidth!='undefined' ? window.outerWidth : document.documentElement.clientWidth;
		    var f = typeof window.outerHeight != 'undefined' ? window.outerHeight: (document.documentElement.clientHeight - 22);
		    var h = (a < 0) ? window.screen.width + a : a;
		    var left = parseInt(h + ((g - width) / 2), 10);
		    var top = parseInt(i + ((f-height) / 2.5), 10);
		    return 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',scrollbars=1,location=no,resizable=no';
		}
	};
	$.extend({
		extendWindow: function(url, option){
			return new ExtendWindow(url, option);
		}
	})
	return ExtendWindow;
});
